<?php
namespace backend\models\system;
use backend\models\system\BannerGroup;
use Yii;
use yii\db\ActiveRecord;

class Banner extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'edu_banner';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['group_id'], 'required'],
            [['banner_title','banner_thumb', 'banner_url'], 'string', 'max' => 120],
            [['banner_desc'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'banner_id' => 'Banner ID',
            'banner_title' => '轮播图标题',
            'banner_desc' => '轮播图描述',
            'banner_thumb' => '轮播图',
            'banner_url' => '轮播图链接',
            'group_id' => '轮播图组',
        ];
    }
    /**
     * 轮播列表查询
     */
    static public function getGroups()
    {
        //return $this->find()->asarray()->all();
        return Banner::find()
	                ->leftJoin("`edu_banner_group` on `edu_banner`.`group_id` = `edu_banner_group`.`group_id`")
	                ->where("`edu_banner_group`.`group_isshow` = 1")
	                ->asArray()
	                ->all();
    }
}